package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.request.KeySynchroniseRequest;
import cc.rengu.igas.bomp.facade.response.KeySynchroniseResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;
import com.alibaba.fastjson.JSON;

/**
 * @author Xuegui Cao
 * @date 2020/7/13
 * @description 密钥同步
 */
public class KeySynchroniseService extends ManageService {
    private static final String PAY_ESB_KEY_LABEL = "LM800BR0492";

    @Override
    protected Object bizBeforeCust() throws Exception {
        KeySynchroniseRequest keySynchroniseRequest = new KeySynchroniseRequest();
        ConvertUtil.convertOutput(keySynchroniseRequest);
        return keySynchroniseRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        KeySynchroniseRequest keySynchroniseRequest = (KeySynchroniseRequest) request;
        KeySynchroniseResponse keySynchroniseResponse = new KeySynchroniseResponse();
        BeanUtil.beanCopy(keySynchroniseRequest, keySynchroniseResponse);
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setResult(keySynchroniseResponse);

        rglog.debug("接收报文：<{}>", JSON.toJSONString(keySynchroniseRequest));
        // if (!BompTxnNumEnum.KEY_SYNCHRONISE.getTxnNum().equals(queryBankToClientMcStatRequest.getHeader().getTxnNum())) {
        //     throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        // }
        DubboService dubboService = new DubboServiceImpl();
        //TODO 密钥同步
        bizResponse.setRespCode(keySynchroniseResponse.getRespCode());
        bizResponse.setRespDesc(keySynchroniseResponse.getRespDesc());
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        KeySynchroniseResponse keySynchroniseResponse = (KeySynchroniseResponse) bizResponse.getResult();
        ConvertUtil.convertInput(keySynchroniseResponse);
    }
}
